home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 21.3 KB | 907 lines | [TEXT/MPS ] |
- /*
- * File: YourTool.p
- *
- * Note: We designed this template to work with V.U. 2.0. If you have a more
- * recent version of V.U., please look for the current version of this file.
- *
- * To add functionality to this tool, replace all occurrences of 'YourTool'
- * and 'YourService' with your own names and supply the corresponding code.
- *
- * Contains: V.U. 2.0 External Tool Pascal Template.
- *
- * This program receives and responsds to Apple Events using the
- * V.U. 2.0 external tool Interface protocol.
- *
- * Written by: Automation Systems Team, Apple Computer, Inc.
- *
- */
-
- PROGRAM YourTool;
-
- USES
- Types,
- Memory,
- Packages,
- Errors,
- QuickDraw,
- Fonts,
- Dialogs,
- Windows,
- Menus,
- Events,
- OSEvents,
- Desk,
- DiskInit,
- Resources,
- ToolUtils,
- AppleEvents,
- EPPC,
- GestaltEqu,
- PPCToolbox,
- Processes,
- VUAE;
-
- CONST
- kMBarID = 128;
- kAppleMenu = 128;
- kFileMenu = 129;
- kEditMenu = 130;
- kNumberOfServices = 7;
-
- TYPE
- ServiceInfo = RECORD
- serviceName : Str255;
- END;
-
- VAR
- hasAE : BOOLEAN;
- quitting : BOOLEAN;
- background : BOOLEAN;
- theMenuBar : Handle;
- appleMenu : MenuHandle;
- fileMenu : MenuHandle;
- editMenu : MenuHandle;
- theEvent : EventRecord; { the current event }
- aeError : OSErr; { the most recent apple event error }
- serviceArray: ARRAY[1..kNumberOfServices] OF ServiceInfo;
-
-
- PROCEDURE Idling;
- {
- We don't do anything while idling. Perhaps we should sing a song?
- }
- BEGIN
- END {Idling};
-
-
- PROCEDURE InvokeDA (theMenu: MenuHandle; theItem: LONGINT);
- {
- Bring up a desk accessory.
- }
- VAR
- err : OSErr;
- da : Str255;
- BEGIN
- GetItem(theMenu, theItem, da);
- err := OpenDeskAcc(da);
- END {InvokeDA};
-
-
- PROCEDURE MenuCommand (theCmd: LONGINT);
- {
- Activate the appropriate menu item.
- }
- VAR
- menuID : LONGINT;
- menuItem: LONGINT;
- dontCare: INTEGER;
- BEGIN
- menuID := HiWord(theCmd);
- menuItem := LoWord(theCmd);
- CASE menuID OF
- kAppleMenu:
- IF menuItem <> 1 THEN InvokeDA(appleMenu, menuItem)
- ELSE dontCare := Alert(666, NIL);
- kFileMenu: quitting := TRUE;
- kEditMenu: ;
- END;
- HiliteMenu(0);
- END {MenuCommand};
-
-
- PROCEDURE DispatchMouseDown (theEvent: EventRecord);
- {
- Dispatch a mouse down event to the proper handler.
- }
- VAR
- theWindow : WindowPtr;
- BEGIN
- CASE FindWindow(theEvent.where, theWindow) OF
- inMenuBar: MenuCommand(MenuSelect(theEvent.where));
- inSysWindow: SystemClick(theEvent, theWindow);
- inDrag:
- IF theWindow = FrontWindow THEN
- DragWindow(theWindow, theEvent.where, screenBits.bounds);
- inContent, inDesk, inGrow, inGoAway: ;
- END;
- END {DispatchMouseDown};
-
-
- PROCEDURE DispatchKeyDown (theEvent: EventRecord);
- {
- Dispatch a key down event to the proper handler. Since typing
- isn't supported, the routine only checks for command key equivalents.
- }
- VAR
- key : CHAR;
- BEGIN
- key := CHR(BAND(theEvent.message, charCodeMask));
- IF (BAND(theEvent.modifiers, cmdKey ) <> 0) & (theEvent.what = keyDown) THEN
- MenuCommand(MenuKey(key));
- END {DispatchKeyDown};
-
-
- PROCEDURE ActivateWindow (theWindow: WindowPtr; activating: BOOLEAN);
- {
- Gee, we don't have any windows worth activating.
- }
- BEGIN
- { we don't have any windows to activate }
- END {ActivateWindow};
-
-
- PROCEDURE UpdateWindow (theWindow: WindowPtr);
- {
- Gee, we don't have any windows worth updating.
- }
- BEGIN
- { we don't have any windows to update }
- END {UpdateWindow};
-
-
- PROCEDURE DiskInserted (diskInfo: LONGINT);
- {
- Handle disk insert errors.
- }
- VAR
- where : Point;
- dontCare: OSErr;
- BEGIN
- IF HiWord(diskInfo) <> noErr THEN BEGIN
- SetPt(where, 40, 40);
- dontCare := DIBadMount(where, diskInfo);
- END;
- END {DiskInserted};
-
-
- PROCEDURE DispatchOSEvent (theEvent: EventRecord);
- {
- Dispatch OS events.
- }
- BEGIN
- CASE BAND(BROTL(theEvent.message, 8), $FF) OF
- mouseMovedMessage:
- Idling;
-
- suspendResumeMessage: BEGIN
- background := BAND(theEvent.message, resumeFlag) = 0;
- ActivateWindow(FrontWindow, NOT background);
- END;
- END;
- END {DispatchOSEvent};
-
-
- PROCEDURE DispatchHighEvent (theEvent: EventRecord);
- {
- Send off those Apple Events!
- }
- BEGIN
- aeError := AEProcessAppleEvent(theEvent);
- END {DispatchHighEvent};
-
-
- PROCEDURE InitializeServiceArray;
- BEGIN
- serviceArray[1].serviceName := 'Initialize';
- serviceArray[2].serviceName := 'Cancel';
- serviceArray[3].serviceName := 'GetToolServices';
- serviceArray[4].serviceName := 'GetToolVersion';
- serviceArray[5].serviceName := 'ServiceSupported';
- serviceArray[6].serviceName := 'Quit';
- { Your services follow. }
- serviceArray[7].serviceName := 'YourService';
- END;
-
-
- PROCEDURE ReportError (err: OSErr; where: LONGINT);
- {
- Reports an error by way of an Alert dialog. "err" is the error
- code. "where" is an arbitrary (but unique) number indicating
- where in the program the error occurred. Of course, if there
- is no error, this routine does nothing.
- }
- VAR
- dontCare: INTEGER;
- errStr : Str255;
- whereStr: Str255;
- BEGIN
- IF err <> 0 THEN BEGIN
- NumToString(err, errStr);
- NumToString(where, whereStr);
- ParamText(errStr, whereStr, '', '');
- dontCare := Alert(128, NIL);
- END {--if};
- END {ReportError};
-
-
- FUNCTION ExtractShortFromAEList(paramList : AEDescList; index : LongInt; VAR result : Integer) : OSErr;
-
- VAR
- aeErr : OSErr;
- paramKeyword: AEKeyword;
- actualType : DescType;
- actualSize : Size;
-
- BEGIN
- aeErr := AEGetNthPtr(paramList,
- index,
- typeShortInteger,
- paramKeyword,
- actualType,
- @result,
- SIZEOF(INTEGER),
- actualSize);
- IF aeErr <> noErr THEN
- ReportError(aeErr, 13);
-
- ExtractShortFromAEList := aeErr;
- END;
-
-
- FUNCTION ExtractStr255FromAEList(paramList : AEDescList; index : LongInt; VAR result : Str255) : OSErr;
-
- VAR
- aeErr : OSErr;
- paramKeyword: AEKeyword;
- actualType : DescType;
- actualSize : Size;
-
- BEGIN
- aeErr := AEGetNthPtr(paramList,
- index,
- typeChar,
- paramKeyword,
- actualType,
- VUStr255ToPtr(result),
- SIZEOF(Str255),
- actualSize);
- IF aeErr <> noErr THEN
- ReportError(aeErr, 14)
- ELSE
- result[0] := CHAR(actualSize);
-
- ExtractStr255FromAEList := aeErr;
- END;
-
-
- PROCEDURE AskForMoreTime( requestedExtraTime : integer; reply : AppleEvent );
- VAR
- moreTimeRequestEvent : AppleEvent;
- dummyReply : AppleEvent;
- aeErr : OSErr;
- vuEventId : OSType;
- extraTime : LongInt;
-
- BEGIN
- aeErr := AEDuplicateDesc( reply, moreTimeRequestEvent );
- IF( aeErr <> noErr ) THEN
- BEGIN
- ReportError( aeErr, 50 );
- END
- ELSE
- BEGIN
- vuEventId := kVUAEWaitLonger;
- aeErr := AEPutAttributePtr( moreTimeRequestEvent,
- keyEventIDAttr,
- typeType,
- @vuEventId,
- SIZEOF( OSType ) );
- IF ( aeErr <> noErr) THEN
- BEGIN
- ReportError( aeErr, 51 );
- END;
-
- extraTime := requestedExtraTime;
- aeErr := AEPutParamPtr( moreTimeRequestEvent, kVUAEWaitAmount, typeMagnitude,
- @extraTime, SIZEOF( extraTime ) );
- IF ( aeErr <> noErr ) THEN
- BEGIN
- ReportError( aeErr, 52 );
- END;
-
- aeErr := AESend( moreTimeRequestEvent,
- dummyReply,
- kAENoReply + kAENeverInteract,
- kAENormalPriority,
- kNoTimeOut,
- Nil,
- Nil );
- IF ( aeErr <> noErr ) THEN
- BEGIN
- ReportError( aeErr, 53 );
- END;
-
- aeErr := AEDisposeDesc( moreTimeRequestEvent );
- IF ( aeErr <> noErr) THEN
- BEGIN
- ReportError( aeErr, 54 );
- END;
- END;
- END;
-
-
- FUNCTION AEOpenHandler (msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- {
- Standard (empty) handler for the 'oapp' Apple Event. Our program does
- not need anything special here, so "noErr" can simply be returned.
- }
- BEGIN
- AEOpenHandler := noErr;
- END {AEOpenHandler};
-
-
- FUNCTION AEOpenDocHandler (msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- {
- Standard (empty) handler for the 'odoc' Apple Event. Our program does
- not have documents, so we ignore this Apple Event.
- }
- BEGIN
- AEOpenDocHandler := noErr;
- END {AEOpenDocHandler};
-
-
- FUNCTION AEQuitHandler (msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- {
- Standard handler for the 'quit' Apple Event. You must never, ever call
- ExitToShell from within an Apple Event handler. It is certain death
- for you application. Thus, we just set a flag which is examined later
- in the main event loop.
- }
- BEGIN
- quitting := TRUE;
- AEQuitHandler := noErr;
- END {AEQuitHandler};
-
-
- FUNCTION AEPrintHandler (msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- {
- Standard (empty) handler for the 'pdoc' Apple Event. Our program does
- not have documents, so we ignore this Apple Event.
- }
- BEGIN
- AEPrintHandler := noErr;
- END {AEPrintHandler};
-
-
- FUNCTION VUInitializeHandler (msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- BEGIN
- VUInitializeHandler := noErr;
- END;
-
-
- FUNCTION VUCancelHandler (msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- BEGIN
- VUCancelHandler := noErr;
- END;
-
-
- FUNCTION VUQuitHandler (msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- BEGIN
- quitting := True;
- VUQuitHandler := noErr;
- END;
-
-
- FUNCTION VUVersionHandler (msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- {
- This Apple Event handler responds to the messages with event class 'v.u.'
- and event id 'vers'. This AppleEvent asks an external tool to respond
- with version information about itself.
-
- The tool name is used by V.U. 2.0 as the name of a tool as shown to a user.
- Thus, this should be something descriptive; e.g., 'Screen Capture Tool'.
-
- The version number is simply a number returned to the caller indicating
- the version of the tool. A V.U. 2.0 script writer could perhaps used this
- information in verifying that the current release of an external tool was
- present.
-
- The version string simply allows more information to be sent by the external
- tool. V.U. 2.0 does not use the version string.
-
- Notice that we must convert the Pascal strings into a format acceptable to
- the Apple Event Manager. Otherwise, the routine simply stuffs values into
- the Apple Event reply using Apple Event Manager routines.
- }
- VAR
- toolName, shortVersion, longVersion : Str255;
- aeErr : OSErr;
- ignore : OSErr;
- srvcList : AEDescList;
-
- BEGIN
- aeErr := AECreateList( NIL, 0, FALSE, srvcList );
- IF aeErr <> noErr THEN
- BEGIN
- ReportError( aeErr, 3 );
- VUVersionHandler := aeErr;
- EXIT(VUVersionHandler);
- END;
-
- toolName := 'YourToolP';
- aeErr := AEPutPtr( srvcList,
- 1,
- typeChar,
- VUStr255ToPtr(toolName),
- Length(toolName) );
-
- IF aeErr <> noErr THEN
- BEGIN
- ReportError( aeErr, 4 );
- END
- ELSE
- BEGIN
- shortVersion := '2.0';
- aeErr := AEPutPtr( srvcList,
- 2,
- typeChar,
- VUStr255ToPtr(shortVersion),
- Length(shortVersion) );
- IF aeErr <> noErr THEN
- BEGIN
- ReportError( aeErr, 5 );
- END
- ELSE
- BEGIN
- longVersion := '2.0ct by Automation Systems, Apple Computer, Inc.';
- aeErr := AEPutPtr( srvcList,
- 3,
- typeChar,
- VUStr255ToPtr(longVersion),
- Length(longVersion) );
- IF aeErr <> noErr THEN
- BEGIN
- ReportError( aeErr, 6 );
- END
- ELSE
- BEGIN
- aeErr := AEPutKeyDesc( reply,
- kVUAESrvcResults,
- srvcList );
- IF aeErr <> noErr THEN
- BEGIN
- ReportError( aeErr, 6 );
- END;
- END;
- END;
- END;
-
- ignore := AEDisposeDesc(srvcList);
- VUVersionHandler := aeErr;
- END;
-
-
- FUNCTION VUHasSrvcHandler (msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- {
- The routine first extracts the command name from the Apple Event. If the
- command name cannot be extracted for some reason from the Apple Event,
- a standard error reply message is sent back to V.U. 2.0.
-
- The routine simply returns the AppleEvent standard types 'typeTrue' or
- 'typeFalse' depending on whether the command name is supported by the
- tool or not. The Apple Event Manager will coerce these standard types
- into an Apple Event Boolean value if necessary (and requested by V.U. 2.0).
- }
- VAR
- actualSize : Size;
- aeErr : OSErr;
- ignore : OSErr;
- actualType : DescType;
- paramList : AEDescList;
- numParams : LONGINT;
- serviceName : Str255;
- i : Integer;
-
- BEGIN
- aeErr := AEGetParamDesc(msg,
- kVUAESrvcParameters,
- typeAEList,
- paramList);
-
- IF aeErr <> noErr THEN
- BEGIN
- ReportError(aeErr, 98);
- VUHasSrvcHandler := aeErr;
- EXIT(VUHasSrvcHandler);
- END;
-
- aeErr := AECountItems(paramList, numParams);
-
- IF aeErr <> noErr THEN
- BEGIN
- ReportError( aeErr, 15 );
- END
- ELSE IF numParams <> 1 THEN
- BEGIN
- aeErr := VUErrorReply(reply, 'Incorrect number of parameters supplied.', errAEWrongParameters );
- IF aeErr <> noErr THEN
- BEGIN
- ReportError( aeErr, 16 );
- END;
- aeErr := errAEWrongParameters;
- END
- ELSE
- BEGIN
- aeErr := ExtractStr255FromAEList(paramList, 1, serviceName);
- IF aeErr <> noErr THEN
- BEGIN
- ReportError(aeErr, 17);
- END;
- END;
-
- ignore := AEDisposeDesc(paramList);
- IF ignore <> noErr THEN
- BEGIN
- ReportError(aeErr, 8);
- END;
-
- IF aeErr <> noErr THEN
- BEGIN
- ReportError(aeErr, 8);
- aeErr := VUErrorReply(reply, 'No service name parameter supplied!', aeErr);
- VUHasSrvcHandler := aeErr;
- EXIT(VUHasSrvcHandler);
- END;
-
- FOR i := 1 TO kNumberOfServices DO
- BEGIN
- IF relstring(serviceName, serviceArray[i].serviceName, false, true) = 0 THEN
- BEGIN
- aeErr := AEPutParamPtr( reply,
- kVUAESrvcResults,
- typeTrue,
- NIL,
- 0);
- VUHasSrvcHandler := aeErr;
- EXIT(VUHasSrvcHandler);
- END;
- END;
-
- aeErr := AEPutParamPtr( reply,
- kVUAESrvcResults,
- typeFalse,
- NIL,
- 0);
-
- IF aeErr <> noErr THEN
- BEGIN
- ReportError(aeErr, 9);
- END;
-
- VUHasSrvcHandler := aeErr;
-
- END {VUHasSrvcHandler};
-
-
- FUNCTION VUSrvcListHandler (msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- {
- This Apple Event handler responds to the messages with event class 'v.u.'
- and event id 'cmdl'. This AppleEvent asks an external tool for a list of
- all command names supported by the tool.
-
- Remember that Apple Event Lists are all one (1) based; i.e., indexes
- start from one (not zero).
-
- The first step creates an Apple Event List descriptor. This is followed by
- stuffing each command name into the list, starting at index number one.
- Once the list if filled with the command names, the list itself is inserted
- into the Apple Event reply.
- }
- VAR
- aeErr : OSErr;
- ignore: OSErr;
- srvcList : AEDescList;
- serviceName : Str255;
- i : Integer;
-
- BEGIN
- aeErr := AECreateList( NIL, 0, FALSE, srvcList );
- IF aeErr <> noErr THEN
- BEGIN
- ReportError( aeErr, 10 );
- VUSrvcListHandler := aeErr;
- EXIT(VUSrvcListHandler);
- END;
-
- FOR i := 1 TO kNumberOfServices DO
- BEGIN
- serviceName := serviceArray[i].serviceName;
- aeErr := AEPutPtr( srvcList,
- i,
- typeChar,
- VUStr255ToPtr(serviceName),
- Length(serviceName) );
- IF aeErr <> noErr THEN
- BEGIN
- ReportError( aeErr, 11 );
- ignore := AEDisposeDesc( srvcList );
- VUSrvcListHandler := aeErr;
- EXIT(VUSrvcListHandler);
- END;
- END;
-
- aeErr := AEPutKeyDesc( reply,
- kVUAESrvcResults,
- srvcList );
- IF aeErr <> noErr THEN
- BEGIN
- ReportError( aeErr, 12 );
- END;
-
- ignore := AEDisposeDesc(srvcList);
-
- VUSrvcListHandler := aeErr;
- END {VUSrvcListHandler};
-
-
- FUNCTION YourService (msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- {
- This is an example service which adds two integers.
- }
- VAR
- aeErr : OSErr;
- ignore : OSErr;
- paramList : AEDescList;
- numParams : LONGINT;
- leftNumber : INTEGER;
- rightNumber : INTEGER;
- result : INTEGER;
-
- BEGIN
- aeErr := AEGetParamDesc(msg,
- kVUAESrvcParameters,
- typeAEList,
- paramList);
-
- IF aeErr <> noErr THEN
- BEGIN
- ReportError(aeErr, 14);
- YourService := aeErr;
- EXIT(YourService);
- END;
-
- aeErr := AECountItems(paramList, numParams);
-
- IF aeErr <> noErr THEN
- ReportError(aeErr, 15)
- ELSE IF numParams <> 2 THEN
- BEGIN
- aeErr := VUErrorReply(reply, 'Incorrect number of parameters passed to service', errAEWrongParameters);
- IF aeErr <> noErr THEN
- ReportError(aeErr, 16);
- aeErr := errAEWrongParameters;
- END
- ELSE IF ExtractShortFromAEList( paramList, 1, leftNumber ) <> noErr THEN
- BEGIN
- ReportError(ExtractShortFromAEList( paramList, 1, leftNumber ), 17);
- END
- ELSE IF ExtractShortFromAEList( paramList, 2, rightNumber ) <> noErr THEN
- BEGIN
- ReportError(ExtractShortFromAEList( paramList, 2, rightNumber ), 18);
- END;
-
- ignore := AEDisposeDesc(paramList);
-
- IF aeErr <> noErr THEN
- BEGIN
- YourService := aeErr;
- EXIT(YourService);
- END;
-
- result := leftNumber + rightNumber;
-
- aeErr := AEPutParamPtr(reply,
- kVUAESrvcResults,
- typeShortInteger,
- @result,
- SIZEOF(result));
-
- IF aeErr <> noErr THEN
- BEGIN
- ReportError( aeErr, 19);
- YourService := aeErr;
- EXIT(YourService);
- END;
-
- YourService := aeErr;
- END;
-
-
- FUNCTION VUServiceHandler(msg, reply: AppleEvent; refCon: LONGINT): OSErr;
- VAR
- vuEventClass : OSType;
- aeErr : OSErr;
- serviceName : Str255;
- errStr : Str255;
- actualType : DescType;
- actualSize : Size;
- i : Integer;
- found : boolean;
-
- BEGIN
- aeErr := AEGetParamPtr(msg,
- kVUAESrvcName,
- typeChar,
- actualType,
- VUStr255ToPtr(serviceName),
- 255,
- actualSize);
-
- IF aeErr <> noErr THEN
- ReportError(aeErr, 1);
- ELSE
- BEGIN
- serviceName[0] := CHAR(actualSize);
- vuEventClass := kVUAETool;
- aeErr := AEPutAttributePtr(reply,
- keyEventClassAttr,
- typeType,
- @vuEventClass,
- SIZEOF(OSType));
-
- IF aeErr <> noErr THEN ReportError(aeErr, 2);
-
- VUServiceHandler := errAEUnknownService;
-
- IF (relstring(serviceName, 'Initialize', false, true) = 0) THEN
- VUServiceHandler := VUInitializeHandler(msg, reply, refcon)
- ELSE
- IF (relstring(serviceName, 'Cancel', false, true) = 0) THEN
- VUServiceHandler := VUCancelHandler(msg, reply, refcon)
- ELSE
- IF (relstring(serviceName, 'GetToolServices', false, true) = 0) THEN
- VUServiceHandler := VUSrvcListHandler(msg, reply, refcon)
- ELSE
- IF (relstring(serviceName, 'GetToolVersion', false, true) = 0) THEN
- VUServiceHandler := VUVersionHandler(msg, reply, refcon)
- ELSE
- IF (relstring(serviceName, 'ServiceSupported', false, true) = 0) THEN
- VUServiceHandler := VUHasSrvcHandler(msg, reply, refcon)
- ELSE
- IF (relstring(serviceName, 'Quit', false, true) = 0) THEN
- VUServiceHandler := VUQuitHandler(msg, reply, refcon)
- ELSE
- IF (relstring(serviceName, 'YourService', false, true) = 0) THEN
- VUServiceHandler := YourService(msg, reply, refcon)
- ELSE
- BEGIN
- ReportError(aeErr, 1984);
- END;
-
- END;
- END;
-
-
- PROCEDURE InitAEStuff;
- {
- Initialization of the Apple Event Manager and dispatch table.
- If we don't have Apple Events or installation of any of the
- Apple Event handlers fails, the program is simply terminated.
- The routine starts by installing standard handlers for the
- core Apple Events. This is followed by installation of the
- event handlers for the V.U. 2.0 external tool interface.
- }
- VAR
- response: LONGINT;
- aeErr : OSErr;
- BEGIN
- hasAE := Gestalt(gestaltAppleEventsAttr, response) = noErr;
- IF hasAE THEN BEGIN
- aeErr := AEInstallEventHandler(kCoreEventClass,
- kAEOpenApplication,
- @AEOpenHandler,
- 0, FALSE);
- IF aeErr <> noErr THEN ExitToShell;
- aeErr := AEInstallEventHandler(kCoreEventClass,
- kAEOpenDocuments,
- @AEOpenDocHandler,
- 0, FALSE);
- IF aeErr <> noErr THEN ExitToShell;
- aeErr := AEInstallEventHandler(kCoreEventClass,
- kAEQuitApplication,
- @AEQuitHandler,
- 0, FALSE);
- IF aeErr <> noErr THEN ExitToShell;
- aeErr := AEInstallEventHandler(kCoreEventClass,
- kAEPrintDocuments,
- @AEPrintHandler,
- 0, FALSE);
- IF aeErr <> noErr THEN ExitToShell;
- aeErr := AEInstallEventHandler(kVUAETool,
- kVUAESendService,
- @VUServiceHandler,
- 0, FALSE);
- IF aeErr <> noErr THEN ExitToShell;
- aeErr := AESetInteractionAllowed(kAEInteractWithAll);
- IF aeErr <> noErr THEN ExitToShell;
- END
- ELSE BEGIN
- ExitToShell;
- END {--if};
- END {InitAEStuff};
-
-
- PROCEDURE BuildMenuBar;
- {
- Construct a menu bar for our application. (Yawn)
- }
- BEGIN
- theMenuBar := GetNewMBar(kMBarID);
- SetMenuBar(theMenuBar);
- appleMenu := GetMHandle(kAppleMenu);
- fileMenu := GetMHandle(kFileMenu);
- editMenu := GetMHandle(kEditMenu);
- AddResMenu(appleMenu, 'DRVR');
- DrawMenuBar;
- END {BuildMenuBar};
-
-
- PROCEDURE InitProgram;
- {
- Initialize the Macintoshâ„¢ Toolbox and application
- environment.
- }
- BEGIN
- quitting := FALSE;
- background := FALSE;
- MaxApplZone;
- InitGraf(Ptr(@thePort));
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(NIL);
- InitCursor;
-
- InitAEStuff;
- InitializeServiceArray;
- BuildMenuBar;
- END {InitProgram};
-
-
- PROCEDURE MainEventLoop;
- {
- Main event loop. Just get events, and dispatch them to an
- appropriate handler until we get the 'quit' command.
- }
- BEGIN
- REPEAT
- IF WaitNextEvent(everyEvent, theEvent, 30, NIL) THEN
- CASE theEvent.what OF
- nullEvent: Idling;
- mouseDown: DispatchMouseDown(theEvent);
- keyDown, autoKey: DispatchKeyDown(theEvent);
- activateEvt: ActivateWindow(WindowPtr(theEvent.message),
- BAND(theEvent.modifiers, activeFlag) <> 0);
- updateEvt: UpdateWindow(WindowPtr(theEvent.message));
- diskEvt: DiskInserted(theEvent.message);
- osEvt: DispatchOSEvent(theEvent);
- kHighLevelEvent: DispatchHighEvent(theEvent);
- END;
- UNTIL quitting;
- END {MainEventLoop};
-
- BEGIN
- InitProgram;
- MainEventLoop;
- END.